package com.venn.controller;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;


/**
 * Created by venn on 12/19/2016.
 */
@Controller
@RequestMapping("/hello")
public class HelloMvcController {

    private static Logger log = LoggerFactory.getLogger(HelloMvcController.class);

    @RequestMapping("/mvc")
    // host:8080/hello/mvc
    public String helloMvc(){
        return "home";
    }

    //本方法将处理 /courses/view?courseId=123 形式的URL
    @RequestMapping(value="/view", method=RequestMethod.GET)
    public String viewCourse(@RequestParam("courseId") Integer courseId,
                             Model model) {


        log.debug("In viewCourse, courseId = {}", courseId);
//        Course course = courseService.getCoursebyId(courseId);
//        model.addAttribute(course);
        return "course_overview";
    }

    //本方法将处理 /courses/view2/123 形式的URL
    @RequestMapping("/view2/{courseId}")
    public String viewCourse2(@PathVariable("courseId") Integer courseId,
                              Map<String, Object> model) {

        log.debug("In viewCourse2, courseId = {}", courseId);
//        Course course = courseService.getCoursebyId(courseId);
//        model.put("course",course);
        return "course_overview";
    }
    private String courseId;

    public String getCourseId() {
        return courseId;
    }

    public void setCourseId(String courseId) {
        this.courseId = courseId;
    }


}
